﻿Option Explicit On
Option Strict On

Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels

Imports ACOMDirector
Imports ACOMDirector.Framework.Hardware
Imports ACOMDirector.Framework.Hardware.Remoting
Imports ACOMDirector.Configuration

Public Class ControlPanelMini

#Region " Private Members "

    Private m_StateManager As StateManagerRemotableWrapper
    Private m_CurrentLocation As Drawing.Point

    'Auto Determine Operate Mode
    Private m_DisableEvents As Boolean = False
    Private m_DoNotRefresh As Boolean = False

    'Matrix Display Line Indexes
    Private m_DisplayLine1Index As Integer
    Private m_DisplayLine2Index As Integer
    Private m_DisplayLine3Index As Integer
    Private m_DisplayLine4Index As Integer

#End Region

#Region " Form Events "

    Private Sub MainForm_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        If m_StateManager IsNot Nothing Then
            RemoveHandler m_StateManager.StateChanged, AddressOf StateChangedHandler
            RemoveHandler m_StateManager.ForwardPowerLedChanged, AddressOf ForwardPowerLedChangedHandler
            RemoveHandler m_StateManager.ReflectedPowerLedChanged, AddressOf ReflectedPowerLedChangedHandler

            m_StateManager = Nothing
        End If

        'Save the Window Location
        SystemConfiguration.Instance.ACOMConfiguration.MiniControlPanelLocationX = m_CurrentLocation.X
        SystemConfiguration.Instance.ACOMConfiguration.MiniControlPanelLocationY = m_CurrentLocation.Y
        SystemConfiguration.Instance.ACOMConfiguration.Save()

    End Sub

    Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'Attach the State Manager object
        m_StateManager = Session.GetSession.StateManager
        AddHandler m_StateManager.StateChanged, AddressOf StateChangedHandler
        AddHandler m_StateManager.ForwardPowerLedChanged, AddressOf ForwardPowerLedChangedHandler
        AddHandler m_StateManager.ReflectedPowerLedChanged, AddressOf ReflectedPowerLedChangedHandler

        'Setup the Matrix Display
        MatrixControl.SetLedStyle(LedStyle.Square)
        MatrixControl.LoadFontCollectionFromResource("ACOMDirector.LedMatrixSymbolFile.xml")

        m_DisplayLine1Index = MatrixControl.AddTextItem(m_StateManager.State.DisplayLine1, New Point(0, 0), ItemDirection.Right, ItemSpeed.Idle)
        m_DisplayLine2Index = MatrixControl.AddTextItem(m_StateManager.State.DisplayLine2, New Point(0, 8), ItemDirection.Right, ItemSpeed.Idle)
        m_DisplayLine3Index = MatrixControl.AddTextItem(m_StateManager.State.DisplayLine3, New Point(0, 16), ItemDirection.Right, ItemSpeed.Idle)
        m_DisplayLine4Index = MatrixControl.AddTextItem(m_StateManager.State.DisplayLine4, New Point(0, 24), ItemDirection.Right, ItemSpeed.Idle)

        'Populate the Measurement Metrics
        AddMetricContextMenuItem(MetricAToolStripMenuItem, "Bias", MeasurementMetricType.Bias, AddressOf MetricAHandler)
        AddMetricContextMenuItem(MetricAToolStripMenuItem, "DC Input", MeasurementMetricType.DCInput, AddressOf MetricAHandler)
        AddMetricContextMenuItem(MetricAToolStripMenuItem, "Drive", MeasurementMetricType.Drive, AddressOf MetricAHandler)
        AddMetricContextMenuItem(MetricAToolStripMenuItem, "Frequency", MeasurementMetricType.Frequency, AddressOf MetricAHandler)
        AddMetricContextMenuItem(MetricAToolStripMenuItem, "Forward Power", MeasurementMetricType.ForwardPower, AddressOf MetricAHandler)
        AddMetricContextMenuItem(MetricAToolStripMenuItem, "Filament Voltage", MeasurementMetricType.FilamentVoltage, AddressOf MetricAHandler)
        AddMetricContextMenuItem(MetricAToolStripMenuItem, "Power Gain", MeasurementMetricType.PowerGain, AddressOf MetricAHandler)
        AddMetricContextMenuItem(MetricAToolStripMenuItem, "HV", MeasurementMetricType.HV, AddressOf MetricAHandler)
        AddMetricContextMenuItem(MetricAToolStripMenuItem, "IF Front Tube", MeasurementMetricType.IFFrontTube, AddressOf MetricAHandler)
        AddMetricContextMenuItem(MetricAToolStripMenuItem, "IF Rear Tube", MeasurementMetricType.IFRearTube, AddressOf MetricAHandler)
        AddMetricContextMenuItem(MetricAToolStripMenuItem, "Grid Current", MeasurementMetricType.GridCurrent, AddressOf MetricAHandler)
        AddMetricContextMenuItem(MetricAToolStripMenuItem, "Plate Current", MeasurementMetricType.PlateCurrent, AddressOf MetricAHandler)
        AddMetricContextMenuItem(MetricAToolStripMenuItem, "Screen Current", MeasurementMetricType.ScreenCurrent, AddressOf MetricAHandler)
        AddMetricContextMenuItem(MetricAToolStripMenuItem, "Mains Voltage", MeasurementMetricType.MainsVoltage, AddressOf MetricAHandler)
        AddMetricContextMenuItem(MetricAToolStripMenuItem, "Plate RF Voltage", MeasurementMetricType.PlateRFVoltage, AddressOf MetricAHandler)
        AddMetricContextMenuItem(MetricAToolStripMenuItem, "Reflected Power", MeasurementMetricType.ReflectedPower, AddressOf MetricAHandler)
        AddMetricContextMenuItem(MetricAToolStripMenuItem, "Screen Voltage", MeasurementMetricType.ScreenVoltage, AddressOf MetricAHandler)
        AddMetricContextMenuItem(MetricAToolStripMenuItem, "Front Tube Temp", MeasurementMetricType.FrontTubeTemp, AddressOf MetricAHandler)
        AddMetricContextMenuItem(MetricAToolStripMenuItem, "Rear Tube Temp", MeasurementMetricType.RearTubeTemp, AddressOf MetricAHandler)
        AddMetricContextMenuItem(MetricAToolStripMenuItem, "VSWR", MeasurementMetricType.VSWR, AddressOf MetricAHandler)
        DirectCast(MetricAToolStripMenuItem.DropDownItems("Bias"), ToolStripMenuItem).Checked = True

        AddMetricContextMenuItem(MetricBToolStripMenuItem, "Bias", MeasurementMetricType.Bias, AddressOf MetricBHandler)
        AddMetricContextMenuItem(MetricBToolStripMenuItem, "DC Input", MeasurementMetricType.DCInput, AddressOf MetricBHandler)
        AddMetricContextMenuItem(MetricBToolStripMenuItem, "Drive", MeasurementMetricType.Drive, AddressOf MetricBHandler)
        AddMetricContextMenuItem(MetricBToolStripMenuItem, "Frequency", MeasurementMetricType.Frequency, AddressOf MetricBHandler)
        AddMetricContextMenuItem(MetricBToolStripMenuItem, "Forward Power", MeasurementMetricType.ForwardPower, AddressOf MetricBHandler)
        AddMetricContextMenuItem(MetricBToolStripMenuItem, "Filament Voltage", MeasurementMetricType.FilamentVoltage, AddressOf MetricBHandler)
        AddMetricContextMenuItem(MetricBToolStripMenuItem, "Power Gain", MeasurementMetricType.PowerGain, AddressOf MetricBHandler)
        AddMetricContextMenuItem(MetricBToolStripMenuItem, "HV", MeasurementMetricType.HV, AddressOf MetricBHandler)
        AddMetricContextMenuItem(MetricBToolStripMenuItem, "IF Front Tube", MeasurementMetricType.IFFrontTube, AddressOf MetricBHandler)
        AddMetricContextMenuItem(MetricBToolStripMenuItem, "IF Rear Tube", MeasurementMetricType.IFRearTube, AddressOf MetricBHandler)
        AddMetricContextMenuItem(MetricBToolStripMenuItem, "Grid Current", MeasurementMetricType.GridCurrent, AddressOf MetricBHandler)
        AddMetricContextMenuItem(MetricBToolStripMenuItem, "Plate Current", MeasurementMetricType.PlateCurrent, AddressOf MetricBHandler)
        AddMetricContextMenuItem(MetricBToolStripMenuItem, "Screen Current", MeasurementMetricType.ScreenCurrent, AddressOf MetricBHandler)
        AddMetricContextMenuItem(MetricBToolStripMenuItem, "Mains Voltage", MeasurementMetricType.MainsVoltage, AddressOf MetricBHandler)
        AddMetricContextMenuItem(MetricBToolStripMenuItem, "Plate RF Voltage", MeasurementMetricType.PlateRFVoltage, AddressOf MetricBHandler)
        AddMetricContextMenuItem(MetricBToolStripMenuItem, "Reflected Power", MeasurementMetricType.ReflectedPower, AddressOf MetricBHandler)
        AddMetricContextMenuItem(MetricBToolStripMenuItem, "Screen Voltage", MeasurementMetricType.ScreenVoltage, AddressOf MetricBHandler)
        AddMetricContextMenuItem(MetricBToolStripMenuItem, "Front Tube Temp", MeasurementMetricType.FrontTubeTemp, AddressOf MetricBHandler)
        AddMetricContextMenuItem(MetricBToolStripMenuItem, "Rear Tube Temp", MeasurementMetricType.RearTubeTemp, AddressOf MetricBHandler)
        AddMetricContextMenuItem(MetricBToolStripMenuItem, "VSWR", MeasurementMetricType.VSWR, AddressOf MetricBHandler)
        DirectCast(MetricBToolStripMenuItem.DropDownItems("Bias"), ToolStripMenuItem).Checked = True

        If Not m_StateManager.State.CanConnect Then
            ConnectToolStripMenuItem.Enabled = False
        ElseIf Not m_StateManager.COMPortOpen Then
            ConnectToolStripMenuItem.Enabled = True
        End If
        DisconnectToolStripMenuItem.Enabled = m_StateManager.UIState.DisconnectEnabled

        RefreshStatus()

    End Sub

#End Region

#Region " Shared Methods "

    Private Shared Sub AddMetricContextMenuItem(ByVal Parent As ToolStripMenuItem, ByVal Name As String, ByVal Value As MeasurementMetricType, Handler As EventHandler)
        Dim MenuItem As ToolStripMenuItem = DirectCast(Parent.DropDownItems.Add(Name, Nothing, Handler), ToolStripMenuItem)
        MenuItem.Tag = Value
        MenuItem.Name = Name
    End Sub

    Private Shared Sub SetSelectedMetric(ByVal Metric As MeasurementMetricType, MenuParent As ToolStripMenuItem)
        For Each item As ToolStripMenuItem In MenuParent.DropDownItems
            item.Checked = False
        Next

        Dim ChildItem As ToolStripMenuItem = Nothing
        Select Case Metric
            Case MeasurementMetricType.Bias
                ChildItem = DirectCast(MenuParent.DropDownItems.Item("Bias"), ToolStripMenuItem)
            Case MeasurementMetricType.DCInput
                ChildItem = DirectCast(MenuParent.DropDownItems.Item("DC Input"), ToolStripMenuItem)
            Case MeasurementMetricType.Drive
                ChildItem = DirectCast(MenuParent.DropDownItems.Item("Drive"), ToolStripMenuItem)
            Case MeasurementMetricType.Frequency
                ChildItem = DirectCast(MenuParent.DropDownItems.Item("Frequency"), ToolStripMenuItem)
            Case MeasurementMetricType.ForwardPower
                ChildItem = DirectCast(MenuParent.DropDownItems.Item("Forward Power"), ToolStripMenuItem)
            Case MeasurementMetricType.FilamentVoltage
                ChildItem = DirectCast(MenuParent.DropDownItems.Item("Filament Voltage"), ToolStripMenuItem)
            Case MeasurementMetricType.PowerGain
                ChildItem = DirectCast(MenuParent.DropDownItems.Item("Power Gain"), ToolStripMenuItem)
            Case MeasurementMetricType.HV
                ChildItem = DirectCast(MenuParent.DropDownItems.Item("HV"), ToolStripMenuItem)
            Case MeasurementMetricType.IFFrontTube
                ChildItem = DirectCast(MenuParent.DropDownItems.Item("IF Front Tube"), ToolStripMenuItem)
            Case MeasurementMetricType.IFRearTube
                ChildItem = DirectCast(MenuParent.DropDownItems.Item("IF Rear Tube"), ToolStripMenuItem)
            Case MeasurementMetricType.GridCurrent
                ChildItem = DirectCast(MenuParent.DropDownItems.Item("Grid Current"), ToolStripMenuItem)
            Case MeasurementMetricType.PlateCurrent
                ChildItem = DirectCast(MenuParent.DropDownItems.Item("Plate Current"), ToolStripMenuItem)
            Case MeasurementMetricType.ScreenCurrent
                ChildItem = DirectCast(MenuParent.DropDownItems.Item("Screen Current"), ToolStripMenuItem)
            Case MeasurementMetricType.MainsVoltage
                ChildItem = DirectCast(MenuParent.DropDownItems.Item("Mains Voltage"), ToolStripMenuItem)
            Case MeasurementMetricType.PlateRFVoltage
                ChildItem = DirectCast(MenuParent.DropDownItems.Item("Plate RF Voltage"), ToolStripMenuItem)
            Case MeasurementMetricType.ReflectedPower
                ChildItem = DirectCast(MenuParent.DropDownItems.Item("Reflected Power"), ToolStripMenuItem)
            Case MeasurementMetricType.ScreenVoltage
                ChildItem = DirectCast(MenuParent.DropDownItems.Item("Screen Voltage"), ToolStripMenuItem)
            Case MeasurementMetricType.FrontTubeTemp
                ChildItem = DirectCast(MenuParent.DropDownItems.Item("Front Tube Temp"), ToolStripMenuItem)
            Case MeasurementMetricType.RearTubeTemp
                ChildItem = DirectCast(MenuParent.DropDownItems.Item("Rear Tube Temp"), ToolStripMenuItem)
            Case MeasurementMetricType.VSWR
                ChildItem = DirectCast(MenuParent.DropDownItems.Item("VSWR"), ToolStripMenuItem)
        End Select
        If ChildItem IsNot Nothing Then
            ChildItem.Checked = True
        End If

    End Sub

#End Region

#Region " Private Methods "

    Private Delegate Sub RefreshStatusDelegate()
    Private Sub RefreshStatus()
        If m_DoNotRefresh Then Exit Sub

        If Me.InvokeRequired Then
            ' if operating on a thread, invoke a delegate
            ' on the UI thread.
            Dim omd As RefreshStatusDelegate = _
            New RefreshStatusDelegate(AddressOf RefreshStatus)
            Dim arx As IAsyncResult = Me.BeginInvoke( _
              omd, New Object() {})
            Me.EndInvoke(arx)
            Return
        End If

        m_DisableEvents = True

        If Not m_StateManager.State.CanConnect Then
            ConnectToolStripMenuItem.Enabled = False
        ElseIf Not m_StateManager.COMPortOpen Then
            ConnectToolStripMenuItem.Enabled = True
        End If

        SetSelectedMetric(m_StateManager.State.MetricA, MetricAToolStripMenuItem)
        SetSelectedMetric(m_StateManager.State.MetricB, MetricBToolStripMenuItem)

        SelectAntenna0ToolStripMenuItem.Enabled = m_StateManager.UIState.Antenna0Enabled
        SelectAntenna1ToolStripMenuItem.Enabled = m_StateManager.UIState.Antenna1Enabled
        SelectAntenna2ToolStripMenuItem.Enabled = m_StateManager.UIState.Antenna2Enabled
        SelectAntenna3ToolStripMenuItem.Enabled = m_StateManager.UIState.Antenna3Enabled
        SelectAntenna4ToolStripMenuItem.Enabled = m_StateManager.UIState.Antenna4Enabled
        SelectAntenna5ToolStripMenuItem.Enabled = m_StateManager.UIState.Antenna5Enabled
        SelectAntenna6ToolStripMenuItem.Enabled = m_StateManager.UIState.Antenna6Enabled
        SelectAntenna7ToolStripMenuItem.Enabled = m_StateManager.UIState.Antenna7Enabled
        SelectAntenna8ToolStripMenuItem.Enabled = m_StateManager.UIState.Antenna8Enabled
        SelectAntenna9ToolStripMenuItem.Enabled = m_StateManager.UIState.Antenna9Enabled
        ConnectToolStripMenuItem.Enabled = m_StateManager.UIState.ConnectEnabled
        DisconnectToolStripMenuItem.Enabled = m_StateManager.UIState.DisconnectEnabled

        MetricAToolStripMenuItem.Enabled = m_StateManager.UIState.MetricASelectionEnabled
        MetricBToolStripMenuItem.Enabled = m_StateManager.UIState.MetricBSelectionEnabled

        cmdOnOff.Enabled = m_StateManager.UIState.OnOffEnabled
        cmdOperateStandby.Enabled = m_StateManager.UIState.OperateStandbyEnabled
        StartMeasurementToolStripMenuItem.Enabled = m_StateManager.UIState.StartMeasuringEnabled
        StopMeasurementToolStripMenuItem.Enabled = m_StateManager.UIState.StopMeasuringEnabled

        MatrixControl.SetItemText(m_DisplayLine1Index, m_StateManager.State.DisplayLine1)
        MatrixControl.SetItemText(m_DisplayLine2Index, m_StateManager.State.DisplayLine2)
        MatrixControl.SetItemText(m_DisplayLine3Index, m_StateManager.State.DisplayLine3)
        MatrixControl.SetItemText(m_DisplayLine4Index, m_StateManager.State.DisplayLine4)

        ledPower.State = m_StateManager.State.PowerLED
        ledOperate.State = m_StateManager.State.OperateLED
        ledStandby.State = m_StateManager.State.StandbyLED
        ledPlate.State = m_StateManager.State.PlateLED
        ledDrive.State = m_StateManager.State.DriveLED
        ledHeater.State = m_StateManager.State.HeaterLED
        ledProtection.State = m_StateManager.State.ProtectionLED

        m_DisableEvents = False

    End Sub

#End Region

#Region " Event Handlers "

    Private Sub cmdOperateStandby_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOperateStandby.Click
        m_StateManager.OperateStandby()
    End Sub

    Private Sub SelectAntenna0ToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles SelectAntenna0ToolStripMenuItem.Click
        m_StateManager.SelectAntenna0()
    End Sub

    Private Sub SelectAntenna1ToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles SelectAntenna1ToolStripMenuItem.Click
        m_StateManager.SelectAntenna1()
    End Sub

    Private Sub SelectAntenna2ToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles SelectAntenna2ToolStripMenuItem.Click
        m_StateManager.SelectAntenna2()
    End Sub

    Private Sub SelectAntenna3ToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles SelectAntenna3ToolStripMenuItem.Click
        m_StateManager.SelectAntenna3()
    End Sub

    Private Sub SelectAntenna4ToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles SelectAntenna4ToolStripMenuItem.Click
        m_StateManager.SelectAntenna4()
    End Sub

    Private Sub SelectAntenna5ToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles SelectAntenna5ToolStripMenuItem.Click
        m_StateManager.SelectAntenna5()
    End Sub

    Private Sub SelectAntenna6ToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles SelectAntenna6ToolStripMenuItem.Click
        m_StateManager.SelectAntenna6()
    End Sub

    Private Sub SelectAntenna7ToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles SelectAntenna7ToolStripMenuItem.Click
        m_StateManager.SelectAntenna7()
    End Sub

    Private Sub SelectAntenna8ToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles SelectAntenna8ToolStripMenuItem.Click
        m_StateManager.SelectAntenna8()
    End Sub

    Private Sub SelectAntenna9ToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles SelectAntenna9ToolStripMenuItem.Click
        m_StateManager.SelectAntenna9()
    End Sub

    Private Sub cmdOnOff_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOnOff.Click
        'If the power is already on then turn it off?
        If m_StateManager.State.PowerState = PowerState.Connected Then
            If MsgBox("Are you sure you want to turn off the ACOM2000A?", MsgBoxStyle.YesNo, "Turn Off ACOM2000A") = MsgBoxResult.Yes Then
                m_StateManager.OnOff()
            End If
        ElseIf m_StateManager.State.PowerState = PowerState.PoweredOff Then
            If m_StateManager.SupportsRemotePowerOn Then
                If MsgBox("Would you like to remotely turn on the ACOM2000A?", MsgBoxStyle.YesNo, "Turn On ACOM2000A") = MsgBoxResult.Yes Then
                    m_StateManager.OnOff()
                End If
            End If
        End If
    End Sub

    Private Sub ForwardPowerLedChangedHandler(ByVal sender As Object, ByVal e As PowerLedEventArgs)
        meterForwardPower.Level = e.Level
    End Sub

    Private Sub ReflectedPowerLedChangedHandler(ByVal sender As Object, ByVal e As PowerLedEventArgs)
        meterReflectedPower.Level = e.Level
    End Sub

    Private Sub StateChangedHandler(ByVal sender As Object, ByVal e As System.EventArgs)
        RefreshStatus()
    End Sub

    Private Sub cmdCommand_Click(sender As System.Object, e As System.EventArgs) Handles cmdCommand.Click
        ContextMenuStrip1.Show(cmdCommand, 20, 20)
    End Sub

    Private Sub StartMeasurementToolStripMenuItem_Click(sender As Object, e As System.EventArgs) Handles StartMeasurementToolStripMenuItem.Click
        Dim MetricA As MeasurementMetricType = MeasurementMetricType.Bias
        Dim MetricB As MeasurementMetricType = MeasurementMetricType.Bias
        For Each item As ToolStripMenuItem In MetricAToolStripMenuItem.DropDownItems
            If item.Checked Then
                MetricA = DirectCast(item.Tag, MeasurementMetricType)
            End If
        Next
        For Each item As ToolStripMenuItem In MetricBToolStripMenuItem.DropDownItems
            If item.Checked Then
                MetricB = DirectCast(item.Tag, MeasurementMetricType)
            End If
        Next

        m_StateManager.StartMeasuring(MetricA, MetricB)
    End Sub

    Private Sub MetricAHandler(sender As Object, e As System.EventArgs)
        If m_DisableEvents Then Exit Sub
        Dim NewMetric As MeasurementMetricType = DirectCast(DirectCast(sender, ToolStripMenuItem).Tag, MeasurementMetricType)

        SetSelectedMetric(NewMetric, MetricAToolStripMenuItem)
        m_StateManager.SetMetricA(NewMetric)
    End Sub

    Private Sub MetricBHandler(sender As Object, e As System.EventArgs)
        If m_DisableEvents Then Exit Sub
        Dim NewMetric As MeasurementMetricType = DirectCast(DirectCast(sender, ToolStripMenuItem).Tag, MeasurementMetricType)

        SetSelectedMetric(NewMetric, MetricBToolStripMenuItem)
        m_StateManager.SetMetricB(NewMetric)
    End Sub

    Private Sub StopMeasurementToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles StopMeasurementToolStripMenuItem.Click
        m_StateManager.StopMeasuring()
    End Sub

    Private Sub MainForm_Move(sender As Object, e As System.EventArgs) Handles Me.Move
        If Not Me.WindowState = FormWindowState.Minimized Then
            m_CurrentLocation = New Drawing.Point(Me.Location.X, Me.Location.Y)
        End If
    End Sub

    Private Sub ConnectToolStripMenuItem_Click(sender As Object, e As System.EventArgs) Handles ConnectToolStripMenuItem.Click
        m_StateManager.Connect()
    End Sub

    Private Sub DisconnectToolStripMenuItem_Click(sender As Object, e As System.EventArgs) Handles DisconnectToolStripMenuItem.Click
        m_StateManager.Disconnect()
    End Sub

#End Region

End Class